home *** CD-ROM | disk | FTP | other *** search
- Path: newshost.cyberramp.net!news
- From: sinan@cyberramp.net (John Noland)
- Newsgroups: comp.lang.c
- Subject: Re: goto
- Date: 13 Mar 1996 23:37:47 GMT
- Organization: Prose Software
- Message-ID: <4i7m8b$ij@newshost.cyberramp.net>
- References: <Pine.OSF.3.91.960313102715.10701D-100000@io.UWinnipeg.ca>
- NNTP-Posting-Host: ramp2-1.cyberramp.net
- X-Newsreader: WinVN 0.99.5
-
- In article <Pine.OSF.3.91.960313102715.10701D-100000@io.UWinnipeg.ca>, wsimpson@uwinnipeg.ca says...
- >
- >There was a goto thread lately, and my problem is to state this algorithm
- >cleanly without gotos (which I think is easy, but my attempts have been
- >failures).
- >
- >0. x=0;
- >1. x+=erand(maxmean);
- >2. if (urand2()>rate(x)/maxrate)
- > goto step 1
- >3. if (x<=XMAX)
- > {
- > setdot(x,y,z);
- > goto step 1
- > }
-
-
- This would be one way to do it:
-
- x = 0;
- for (;;) {
- x += erand(maxmean);
- if (urand2() > rate(x)/maxrate)
- continue;
- if (x <= XMAX) {
- setdot(x, y, z);
- continue;
- }
- break;
- }
-
-
- - John
-
-